package com.hooker.util;

import android.content.Context;

import com.hooker.common.StringUtil;
import com.hooker.settings.Setting;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class IO {

    static final int BuffLength = 1024 * 4;

    public static void write(InputStream in, OutputStream out) throws IOException {
        byte[] buff = new byte[BuffLength];
        int buffLen = -1;

        while ((buffLen = in.read(buff, 0, buff.length)) != -1) {
            out.write(buff, 0, buffLen);
        }
    }

    public static String getFromAssets(Context context, String fileName) {
        StringBuilder builder = new StringBuilder();
        try {
            InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName));
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line;
            while ((line = bufReader.readLine()) != null) {
                builder.append(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return builder.toString();
    }
}
